class Solution {
    public String convert(String s, int numRows) {
        if(numRows==1) return s;
        List<StringBuilder> rows = new ArrayList<>();
        for(int i=0;i<numRows;i++)  
            rows.add(new StringBuilder());
        int i=0,flag=-1;
        for(char ch:s.toCharArray()){
            rows.get(i).append(ch);
            if(i==0||i==numRows-1)
                flag=-flag;
            i+=flag;
        }
        StringBuilder ret=new StringBuilder();
        for(StringBuilder x:rows)   ret.append(x);
        return ret.toString();
    }
}